{extend name="public/base"/}
{block name="body"}
<title>设置</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 后台管理 <span class="c-gray en">&gt;</span>设置管理<span class="c-gray en">&gt;</span>设置<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
		<form class="form form-horizontal section" id="form-admin-add">
			<section>
					<input type="hidden" class="input-text" value="{$data.id}" id="id" name="id">
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">网站标题：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.site_title}" id="site_title" name="site_title">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">LOGO：</label>
						<div class="formControls col-xs-8 col-sm-9">
			                <div style="position:relative;" id="drop_area"></div>
			                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:211*24</p>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">SEO关键词：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.seo_keywords}" id="seo_keywords" name="seo_keywords">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">SEO描述：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.seo_description}" id="seo_description" name="seo_description">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">地址：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.address}" id="address" name="address">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">经纬度：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.longitude_latitude}" placeholder="经纬度;例如:30.527540,114.346430" id="longitude_latitude" name="longitude_latitude">
			                     <a href="http://lbs.qq.com/tool/getpoint/" target="_blank">
			                     <p class="dizhi">*点击获取地理位置</p></a>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">联系电话：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.tel}" id="tel" name="tel">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">品牌专线：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.contact_phone}" id="contact_phone" name="contact_phone">
						</div>
					</div>
					<div class="row cl" style="display:none;">
						<label class="form-label col-xs-3 col-sm-2">传真：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.fax}" id="fax" name="fax">
						</div>
					</div>
					<div class="row cl" style="display:none;">
						<label class="form-label col-xs-3 col-sm-2">邮箱：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.email}" id="email" name="email">
						</div>
					</div>
					<div class="row cl" style="display:none;">
						<label class="form-label col-xs-3 col-sm-2">微信公众号：</label>
						<div class="formControls col-xs-8 col-sm-9">
			                <div style="position:relative;" id="drop_wechat"></div>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">电话/微信：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.wechat}" id="wechat" name="wechat">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">QQ：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.qq}" id="qq" name="qq">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">公司copyright：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.copyright}" id="copyright" name="copyright">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">ICP：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="{$data.icp}" id="icp" name="icp">
						</div>
					</div>
			</section>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-3 col-sm-offset-2">
					<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
		</form>
		
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
var nth;
var formDatawechat = new FormData();
var formDatalogo = new FormData();
var logo;
var qrcode_wechat;
$(function(){
	$('#drop_wechat div img').attr('src','{$data.qrcode_wechat}');
	$('#drop_wechat div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_wechat div img").attr('src')=='/static/img/upload.png'){
		qrcode_wechat='';
	}else{
		qrcode_wechat= `{$data.qrcode_wechat}`;
	}
	$('#drop_area div img').attr('src','{$data.logo}');
	$('#drop_area div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_area div img").attr('src')=='/static/img/upload.png'){
		logo='';
	}else{
		logo= `{$data.logo}`;
	}
});
var dragImgUpload = new DragImgUpload("#drop_wechat",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        formDatawechat.append("file",file);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        formDatalogo.append("file",file);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var longitude_latitude=$("input[name=longitude_latitude]").val();
	var tel=$("input[name=tel]").val();
	var site_title=$("input[name=site_title]").val();
	var seo_keywords=$("input[name=seo_keywords]").val();
	var seo_description=$("input[name=seo_description]").val();
	var contact_phone=$("input[name=contact_phone]").val();
	var copyright=$("input[name=copyright]").val();
	var icp=$("input[name=icp]").val();
	var address=$("input[name=address]").val();
	var fax=$("input[name=fax]").val();
	var email=$("input[name=email]").val();
	var qq=$("input[name=qq]").val();
	var wechat=$("input[name=wechat]").val();
	if(formDatawechat.get("file")||formDatalogo.get("file")){
		if(formDatawechat.get("file")){
			$.ajax({
		          type: 'POST',
		          url: "{:url('uploadtmd')}",
		          data:formDatawechat,
		          async:false,
		          contentType: false, /*不可缺*/
		          processData: false, /*不可缺*/
		          success: function(response){
		            if(response.code==200){
		            	qrcode_wechat=response.photo;
		            }
		          },
		          error: function(err){
		          	console.log('qrcode_wechat'+err)
		          }
		    })
		}
		if(formDatalogo.get("file")){
			$.ajax({
		          type: 'POST',
		          url: "{:url('uploadtmd')}",
		          data:formDatalogo,
		          async:false,
		          contentType: false, /*不可缺*/
		          processData: false, /*不可缺*/
		          success: function(response){
		            if(response.code==200){
		            	logo=response.photo;
		            }
		          },
		          error: function(err){
		          	console.log('logo'+err)
		          }
		    })
		}
		$.ajax({
		    type: 'POST',
		    url: "{:url('system_set')}",
		    async:false,
		    data: {tel:tel,copyright:copyright,icp:icp,longitude_latitude:longitude_latitude,address:address,email:email,qrcode_wechat:qrcode_wechat,contact_phone:contact_phone,fax:fax,seo_description:seo_description,seo_keywords:seo_keywords,site_title:site_title,logo:logo,qq:qq,wechat:wechat},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}else{
		$.ajax({
		    type: 'POST',
		    url: "{:url('system_set')}",
		    data: {tel:tel,copyright:copyright,icp:icp,longitude_latitude:longitude_latitude,address:address,email:email,qrcode_wechat:qrcode_wechat,contact_phone:contact_phone,fax:fax,seo_description:seo_description,seo_keywords:seo_keywords,site_title:site_title,logo:logo,qq:qq,wechat:wechat},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}
})
</script> 

{/block}